package com.molyfun.parents.activity.common.listactivity.factory;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.molyfun.parents.MFPApplication;
import com.molyfun.parents.R;
import com.molyfun.parents.activity.common.listactivity.AbstractListFactory;
import com.molyfun.parents.activity.common.listactivity.IResponse;
import com.molyfun.parents.activity.common.listactivity.viewholder.AnnouncementViewHolder;
import com.molyfun.parents.rest.bean.AnnouncementListResponse;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by william(liuchao.hit@gmail.com).
 * 小组-公告
 */
public class AnnouncementFactory extends AbstractListFactory<AnnouncementListResponse.AnnouncementBean> {

    private String mTeamId;

    public AnnouncementFactory(String teamId){
        mTeamId = teamId;
    }

    @Override
    public int getTitle() {
        return R.string.activity_title_mine_announcement;
    }

    @Override
    public void getDataList(int pageNum,final IResponse responseCallback) {


        Call<AnnouncementListResponse> call = MFPApplication.getInstance().getRestClient().getTeamNoticeList(mTeamId, pageNum);
        call.enqueue(new Callback<AnnouncementListResponse>() {
            @Override
            public void onResponse(Call<AnnouncementListResponse> call, Response<AnnouncementListResponse> response) {
                if (response.body() != null) {
                    if(response.body().getData() != null && response.body().getData().size() > 0){
                        if (response.body() != null && response.body().getData() != null && response.body().getData() != null) {
                            responseCallback.onResponse(response.body().getData());
                        }
                    }
                }
            }

            @Override
            public void onFailure(Call<AnnouncementListResponse> call, Throwable t) {

            }
        });
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(ViewGroup parent, int viewType) {
        return new AnnouncementViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_announcement_cell, parent, false));
    }

    @Override
    public void bindViewHolder(final Context context, final AnnouncementListResponse.AnnouncementBean announcementBean, RecyclerView.ViewHolder holder, final int position, FragmentManager fragmentManager, int totalSize) {

        AnnouncementViewHolder announcementViewHolder = (AnnouncementViewHolder)holder;
        if(position == (totalSize - 1)){
            announcementViewHolder.mAnnouncementView.initData(announcementBean, true);
        }else{
            announcementViewHolder.mAnnouncementView.initData(announcementBean, false);
        }
    }

    @Override
    public void deleteData(final String id,final int position) {
    }
}
